package com.jingtao.product.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jingtao.common.core.domain.R;
import com.jingtao.common.core.web.controller.BaseController;
import com.jingtao.common.core.web.domain.AjaxResult;
import com.jingtao.common.log.annotation.Log;
import com.jingtao.common.log.enums.BusinessType;
import com.jingtao.product.domain.Brand;
import com.jingtao.product.domain.vo.BrandVo;
import com.jingtao.product.service.BrandService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName:
 * @Description:
 * @Author: zengfanzhen
 * @Date: 2024/3/28 22:22:51
 */
@RestController
@Api(tags = "品牌管理")
@RequestMapping("/brand")
@Slf4j
public class BrandController extends BaseController {

    @Autowired
    private BrandService brandService;

    @GetMapping("/getBrandList")
    public R<List<Brand>> getBrandList(){
        return R.ok(brandService.getBrandList());
    }

    /**
     * @Description: 根据条件查询品牌信息
     * @Param: [brandVo]
     */
    @PostMapping("/queryBrandList")
    public R queryBrandList(@RequestBody BrandVo brandVo){
        log.info("查询品牌信息：{}", brandVo);
        PageHelper.startPage(brandVo.getPageNum(), brandVo.getPageSize());
        List<Brand> brandList = brandService.queryBrandList(brandVo);
        PageInfo<Brand> brandPageInfo = new PageInfo<>(brandList);
        return R.ok(brandPageInfo);
    }

    /**
     * 获取商品品牌详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(brandService.selectBrandById(id));
    }

    /**
     * 新增商品品牌
     */
    @Log(title = "商品品牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Brand brand)
    {
        return toAjax(brandService.insertBrand(brand));
    }

    /**
     * 修改商品品牌
     */
    @Log(title = "商品品牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Brand brand)
    {
        return toAjax(brandService.updateBrand(brand));
    }

    /**
     * 删除商品品牌
     */
    @Log(title = "商品品牌", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(brandService.deleteBrandByIds(ids));
    }





}
